'use strict';var WPF;
(function(b,p,k,q){WPF={prefix:"wpf_",template_type:!1,init:function(a){a=b.extend({prefix:this.prefix,template_type:this.template_type},a);this.prefix=a.prefix;this.template_type=a.template_type;this.Undelegate();this.bindEvents()},Undelegate:function(){b(k).off("change click")},bindEvents:function(){this.SetupColors();this.InitDraggable();this.InitSortable();this.ShowHide();this.Unique(b("#"+this.prefix+"module_content ."+this.prefix+"back_active_module_content"));this.Open();this.Delete();this.Save();
this.ShowThemplates();this.AddItem();this.RemmoveItem();this.multiLanguages();b.event.trigger("WPF.template_load",this.template_type)},PlaceHoldDragger:function(){b("."+WPF.prefix+"module_holder").each(function(){var a=b(this).find("."+WPF.prefix+"empty_holder_text");0===b(this).find("."+WPF.prefix+"active_module").length?a.show():a.hide()})},InitDraggable:function(){var a=this;b("."+a.prefix+"back_module_panel ."+a.prefix+"back_module").draggable({appendTo:"body",helper:"clone",revert:"invalid",
snapMode:"inner",connectToSortable:"."+a.prefix+"module_holder",stop:function(c,d){c=b(d.helper[0]);var e=c.data("type");0<b("#"+a.prefix+"module_content").find('[data-type="'+e+'"]').length&&(b("#"+a.prefix+"cmb_"+e).hide(),b.event.trigger("WPF.template_drag_start",[c,d,a.template_type]),a.Unique(c),e=c.find("."+a.prefix+"color_picker"),a.DestroyInputColor(e),a.SetInputColor(e),c.find("."+a.prefix+"toggle_module").trigger("click"),b.event.trigger("WPF.template_drag_end",[c,d,a.template_type]))}})},
InitSortable:function(){var a=this;b("."+a.prefix+"module_holder").sortable({placeholder:a.prefix+"ui_state_highlight",items:"."+a.prefix+"back_module",connectWith:"."+a.prefix+"module_holder",cursor:"move",revert:100,axis:"y",cancel:".wpf_active_module",sort:function(c,d){c=d.item.outerHeight();b("."+a.prefix+"module_holder ."+a.prefix+"ui_state_highlight").height(c)},receive:function(c,d){a.PlaceHoldDragger();b(this).parent().find("."+a.prefix+"empty_holder_text").hide();b(d.item).removeClass("dragged")},
start:function(c,d){b(d.item).removeClass(a.prefix+"dragged")},stop:function(c,d){b(d.item).addClass(a.prefix+"dragged")}});b("."+a.prefix+"back_active_module_add").sortable({placeholder:a.prefix+"ui_state_highlight",items:"li",connectWith:"parent",cursor:"move",revert:100,axis:"y"})},ShowHide:function(){b("#"+WPF.prefix+"lightbox_container").on("change","."+WPF.prefix+"changed input,."+WPF.prefix+"changed select",function(){var a=!0;if(b(this).closest("."+WPF.prefix+"show_icons").length&&!b(this).closest("."+
WPF.prefix+"items_container").length){var c=b(this).closest("."+WPF.prefix+"show_icons").find("."+WPF.prefix+"items_container");a=b(this).is(":checked")}else if(0<b(this).closest("."+WPF.prefix+"result_page_wrapper").length&&("wpf_diff_page"==this.id||"wpf_same_page"==this.id))c=b(this).closest("."+WPF.prefix+"result_page_wrapper").find("."+WPF.prefix+"result_page_select"),a="diff_page"===b(this).val();else if(0<b(this).closest("."+WPF.prefix+"grid").length)c=b("#"+WPF.prefix+"group_fields").closest("."+
WPF.prefix+"lightbox_row"),a="vertical"===b(this).val();else if(0<b(this).closest("."+WPF.prefix+"order").length)c=b(this).closest("."+WPF.prefix+"order").next("."+WPF.prefix+"orderby"),a="term_order"!==b(this).val();else if(0<b(this).closest("."+WPF.prefix+"show_range").length){var d=b(this).closest("."+WPF.prefix+"back_active_module_row"),e=d.next("."+WPF.prefix+"group");d=d.nextAll("."+WPF.prefix+"slider");"group"===b(this).val()?(d.slideUp(),e.slideDown()):(e.slideUp(),d.slideDown())}else 0<b(this).closest("."+
WPF.prefix+"display_as").length?(c=b(this).closest("."+WPF.prefix+"back_active_module_content").find("."+WPF.prefix+"icons_block"),e=b(this).val(),a="checkbox"===e||"radio"===e,"dropdown"===e||"radio"===e?b(this).closest("."+WPF.prefix+"back_active_module_content").find("."+WPF.prefix+"show_all_block").show():b(this).closest("."+WPF.prefix+"back_active_module_content").find("."+WPF.prefix+"show_all_block").hide()):"wpf_pagination_fields"===b(this).prop("id")?(c=b(".wpf_infinity"),a=!b(this).is(":checked")):
"pagination_type"===b(this).prop("name")&&("infinity_auto"===b(this).val()?b(".wpf_lightbox_row.wpf_infinity_buffer").show():b(".wpf_lightbox_row.wpf_infinity_buffer").hide());"undefined"!==typeof c&&(a?c.slideDown():c.slideUp())});b("."+WPF.prefix+"changed input:checked,."+WPF.prefix+"changed option:selected").trigger("change")},Open:function(){var a=this;b(k).on("click","."+a.prefix+"toggle_module",function(c){var d=b(this).closest("."+a.prefix+"back_module").find("."+a.prefix+"back_active_module_content");
if(b(this).hasClass(a.prefix+"opened")||d.is(":visible"))b(this).removeClass(a.prefix+"opened"),d.slideUp();else{b(this).addClass(a.prefix+"opened");d.slideDown();const e=d.data("type");if("wpf_cat"===e||"wpf_tag"===e){const f=d[0].getElementsByClassName("wpf_tax_items");f[0]&&f[0].dataset.url&&(d=d[0].querySelector('input[name="['+e+'][color]"]'),d.checked?WPF.getTax(f[0]):d.addEventListener("change",function(){WPF.getTax(f[0])},{once:!0}))}}c.preventDefault()})},Delete:function(){b(k).on("click",
"."+WPF.prefix+"delete_module",function(a){a.preventDefault();confirm(wpf_js.module_delete)&&(a=b(this).closest("."+WPF.prefix+"back_module"),b("#"+WPF.prefix+"cmb_"+a.data("type")).show(),a.remove(),WPF.PlaceHoldDragger())})},Save:function(){var a=this;b("#"+a.prefix+"submit").on("click",function(c){var d=b(this).closest("form"),e=b("."+a.prefix+"back_builder").find("input,select,textarea");e.prop("disabled",!0);setTimeout(function(){var f=a.ParseData();b.event.trigger("WPF.before_template_save",
f);f=JSON.stringify(f);b("#"+a.prefix+"layout").val(f);b.ajax({url:d.prop("action"),method:"POST",dataType:"json",data:d.serialize(),beforeSend:function(){d.removeClass(a.prefix+"done").addClass(a.prefix+"save")},complete:function(){e.prop("disabled",!1);d.removeClass(a.prefix+"save").addClass(a.prefix+"done")},success:function(g){g&&"1"==g.status&&(d.find("#"+a.prefix+"themplate_id").val(g.id),b("#"+a.prefix+"success_text").html("<p><strong>"+g.text+"</strong></p>").show(),setTimeout(function(){b("#"+
a.prefix+"success_text").html("").hide()},2E3),b.event.trigger("WPF.after_template_save"))}})},100);c.preventDefault()})},ParseData:function(){var a={};b("#"+WPF.prefix+"module_content").find("."+WPF.prefix+"back_active_module_content").each(function(){var c=b(this).data("type");a[c]={};b(this).find('input:checked,input[type="text"],input[type="number"],input[type="hidden"],textarea,select').each(function(){var d=b(this).attr("name");if(d){var e=d.split("]");if(e){e.pop();d=[];for(var f in e){var g=
e[f].split("[");g[1]&&(d[f]=g[1])}(f="arr"==d[2])||a[c][d[1]]&&!d[2]?f?(a[c][d[1]]=b(this).val(),a[c][d[1]]||(a[c][d[1]]=[])):("object"!=typeof a[c][d[0]]&&"object"!=typeof a[c][d[1]]&&(f=a[c][d[1]],a[c][d[1]]=[],a[c][d[1]][0]=f),a[c][d[1]].push(b(this).val())):d[2]?(f=d[2],"object"!=typeof a[c][d[1]]&&(a[c][d[1]]={}),a[c][d[1]][f]=b(this).val()):(b(this).hasClass(WPF.prefix+"color_picker")?(f=b(this).minicolors("rgbaString"),f="rgba(0, 0, 0, 1)"!=f||b(this).val()?f:!1):f="on"==b(this).val()?!0:b(this).val(),
a[c][d[1]]=f)}}})});return a},Unique:function(a){a.each(function(){var c=b(this);c.find("label").each(function(){var h=b(this).attr("for");if(h&&(h=WPF.Escape(b(this).attr("for")),0<b("#"+h).length)){var l=WPF.GenerateUnique();c.find("#"+h).attr("id",l);b(this).attr("for",l)}});var d=/.*?\[(.+?)\]/ig,e={};c.find('input[type="radio"]').each(function(h){(h=b(this).attr("name"))&&(e[h]=1)});for(var f in e){var g=f.match(d);if(g){var m=WPF.GenerateUnique(),n=c.find('input:radio[name="'+f+'"]');g=m+g[0]+
g[1];n.attr("name",g);c.find('input:radio[name!="'+f+'"]')&&c.find('input:radio[name="'+g+'"][checked]').prop("checked",!0)}}})},GenerateUnique:function(){return WPF.prefix+Math.random().toString(36).substr(2,9)},Escape:function(a){return a.replace(/(:|\.|\[|\]|,)/g,"\\$1")},SetupColors:function(){b("#"+WPF.prefix+"module_content").find("."+WPF.prefix+"color_picker").each(function(){var a=WPF.RgbaToHex(b(this).data("value"));a&&-1!==a.indexOf("@")&&(a=a.split("@"),b(this).val(a[0]),b(this).attr("data-opacity",
a[1]))});this.SetInputColor()},SetInputColor:function(a){a||(a=b("."+WPF.prefix+"color_picker"));a.minicolors({opacity:!0,position:"top right",theme:"default",show:function(){b("."+WPF.prefix+"module_holder").sortable("disable")},hide:function(){b("."+WPF.prefix+"module_holder").sortable("enable")},create:function(c){}})},DestroyInputColor:function(a){a||(a=b("#"+WPF.prefix+"module_content").find("."+WPF.prefix+"color_picker"));a.minicolors("destroy")},RgbaToHex:function(a){if(!a)return!1;var c=(a=
a.match(/^rgba?[\s+]?\([\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(.*)[\s+]?\)/i))&&3<=a.length?"#"+("0"+parseInt(a[1],10).toString(16)).slice(-2)+("0"+parseInt(a[2],10).toString(16)).slice(-2)+("0"+parseInt(a[3],10).toString(16)).slice(-2):"";c&&a[4]&&(c+="@"+a[4]);return c},ShowThemplates:function(){var a=this.prefix;b(k).on("WPF.close_lightbox",function(c,d){if(b(d).closest(".wpf_admin_lightbox").find("#"+a+"themplate_id").val()){var e=b("#the-list");b.ajax({url:ajaxurl,type:"POST",
data:{action:"wpf_get_list"},beforeSend:function(){e.addClass(a+"wait")},complete:function(){e.removeClass(a+"wait")},success:function(f){f&&e.replaceWith(b(f).find("#the-list"))}})}})},AddItem:function(){b("#"+WPF.prefix+"module_content").on("click","."+WPF.prefix+"add_item",function(a){a.preventDefault();a=b(this).prev("ul").children("li").first().clone();a.hide().find("input").val("");b(this).prev("ul").append(a);a.slideDown()})},RemmoveItem:function(){b("#"+WPF.prefix+"module_content").on("click",
"."+WPF.prefix+"remove_item",function(a){a.preventDefault();b(this).closest("li").slideUp(function(){b(this).remove()})})},multiLanguages:function(){b("body").on("click",".wpf_language_tabs li",function(a){a.preventDefault();a=b(this);if(!a.hasClass("wpf_active_tab_lng")){a.siblings(".wpf_active_tab_lng").removeClass("wpf_active_tab_lng");a.addClass("wpf_active_tab_lng");var c=a.parents(".wpf_language_tabs").parent().find(".wpf_language_fields");c.find("li").removeClass("wpf_active_lng");c.find('li[data-lng="'+
a.children("a").attr("class")+'"]').addClass("wpf_active_lng")}})},getTax:function(a){b.ajax({url:a.dataset.url,success:function(c){c&&(a.innerHTML=c,a.dataset.url="",WPF.multiLanguages(),WPF.SetupColors())}})}}})(jQuery,window,document);
